package com.joseph.websocket.mq;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class Provider {

    public static void main(String[] args) throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("joseph-groupp");
        producer.setNamesrvAddr("localhost:9876");
        producer.setInstanceName("producer");
        producer.start();
        try {
            for (int i = 0; i < 1; i++) {
                Message msg = new Message("joseph-topic", // topic 主题名称
                        "", // tag 临时值
                        ("joseph-data-kkkk-" + i).getBytes()// body 内容
                );
                SendResult sendResult = producer.send(msg);
                producer.send(null, new MessageQueueSelector() {
                    @Override
                    public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
                        return null;
                    }
                }, null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        producer.shutdown();
    }
}
